package udpmessaging;

import com.messaging.UdpMq;
import com.messaging.events.MessageReceiveEvent;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;

/**
 * @author sad
 */
public class TestUdpServerNR {

    public static void main(String[] args) throws Exception {
        System.out.println("Start server");
        UdpMq mq = new UdpMq(9874);
        final int[] array = new int[50000];
        mq.setMessageReceiveEvent(new MessageReceiveEvent() {

            @Override
            public void messageReceive(byte[] buffer, InetAddress sender, int port) throws UnsupportedEncodingException {
                int v = UdpMq.copyIntFromArray(buffer, 0);
                array[v] = 5;
            }
        });

        mq.start();
        Thread.sleep(30000);
        int count = 0;
        for (int i = 0; i < 50000; i++) {
            if (array[i] == 0) {
                System.out.println(i);
                count++;
            }
        }
        System.out.println("End Lost " + count);
        System.exit(0);
    }
}
